<template>
  <div class="flash">
    <div class="flash_operate front-color">
      <div class="cont clearfix">
        <div class="operate">
          <div class="head"><span class="areaTtle">{{$t('myAdd.flash.flash')}}</span></div>
          <p class="rate">{{$t('myAdd.flash.rate')}}≈{{showToUser.floatRate}}</p>
          <div class="operate_cont">
            <div class="line_div clearfix">
              <div class="select">
                <inline-input
                  v-bind:property = "formList.flashCurrency"
                  v-model = "formList.flashCurrency.value"
                  v-on:onevents = "somethings">
                </inline-input>
                <span class="coinImg"><img :src="flashCurrencyCoinImg || coinImg" alt=""></span>
              </div>
              <div class="text">
                <inline-input
                  v-bind:property = "formList.flashNum"
                  v-model = "formList.flashNum.value"
                  v-on:onevents = "somethings">
                </inline-input>
              </div>
            </div>
            <div class="line_div clearfix">
              <div class="select">
                <inline-input
                  v-bind:property = "formList.receivedCurrency"
                  v-model = "formList.receivedCurrency.value"
                  v-on:onevents = "somethings">
                </inline-input>
                <span class="coinImg"><img :src="receivedCurrencyCoinImg || coinImg" alt=""></span>
              </div>
              <div class="text">
                <inline-input
                  v-bind:property = "formList.receivedNum"
                  v-model = "formList.receivedNum.value"
                  v-on:onevents = "somethings">
                </inline-input>
              </div>
            </div>
            <p class="errorInfo" v-if="myData.errInfo">{{myData.errInfo}}</p>
            <div class="reminder">
              <p class="clearfix"><span class="left">{{$t('myAdd.flash.available')}} {{showToUser.balance}}&nbsp;{{showToUser.buySymbol}}</span><span class="right">{{$t('myAdd.flash.serviceFee')}} {{showToUser.fastFee * 100}}%</span></p>
              <p>{{showToUser.fastMinQuantityOnce}} <= {{$t('myAdd.flash.quanty')}} <= {{showToUser.fastMaxQuantityOnce}}</p>
            </div>
            <div class="btn">
              <button class="fastFlash" :class="{readOnly: !isCanFastFlash || !isInputValueYes}" @click="fastFlash">{{$t('myAdd.flash.quickFlash')}}</button> <br/>
              <p class="des">{{$t('myAdd.flash.userDes', {firstAudit: showToUser.firstAudit, buySymbol: showToUser.buySymbol, flashTimeAudit: showToUser.flashTimeAudit, stime: showToUser.stime, etime: showToUser.etime})}}</p>
            </div>
          </div>
        </div>
        <div class="rule borderbox">
          <h1>{{$t('myAdd.flash.ruleDes')}}</h1>
          <div class="scroll">
            <p v-for="(item, index) in flashRule" :key="index">{{item}}</p>
          </div>
        </div>
      </div>
    </div>
    <div class="flash_detail front-color">
      <div class="detail_head clearfix">
        <span class="areaTtle">{{$t('myAdd.flash.flashDetail')}}</span><span class="reviewText" v-if="reviewCount">{{$t('myAdd.flash.youhave')}}<span class="reviewCount"> {{reviewCount}} </span>{{$t('myAdd.flash.unReview')}}</span>
        <div class="ex_symbol">
          <span class="text">{{$t('myAdd.flash.status')}}:</span>
          <inline-input
            v-bind:property = "formStatus.statusChoose"
            v-model = "formStatus.statusChoose.value"
            v-on:onevents = "somethings">
          </inline-input>
        </div>
        <div class="month">
          <span class="text">{{$t('myAdd.flash.date')}}:</span>
          <Datepicker
            :value="dataTimePickerValue"
            name="uniquename"
            :inline="false"
            :minimumView="'month'"
            :maximumView="'month'"
            @selected="chooseMonth"
            :language="dataTimePickerLanguage"
            format="yyyy-MM"
            :disabledDates="disabledDates"
          >
          </Datepicker>
          <span class="iconSpan"><i class="icon-calendar"></i></span>
        </div>
      </div>
      <div class="detail_table">
        <table>
          <thead>
            <tr>
              <td class="time_td">{{$t('myAdd.flash.time')}}</td>
              <td class="flash_td">{{$t('myAdd.flash.exchange')}}</td>
              <td class="get_td">{{$t('myAdd.flash.get')}}</td>
              <td class="status_td">{{$t('myAdd.flash.status')}}</td>
              <td class="operate_td">{{$t('myAdd.flash.operate')}}</td>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, index) in recordList" :key="index">
              <td class="time_td">{{item.ctime}}</td>
              <td class="flash_td">{{item.allBuyNum}}</td>
              <td class="get_td">{{item.sellNum}}</td>
              <td class="status_td">
                <span v-show="item.status === 0">
                  <i class="icon-true_icon1"></i>
                </span>
                <span class="primary status" :class="{cancled: item.status === 3, warning: item.status === 2, reviewColor: item.status === 1}">{{recordListStatus(item.status)}}</span>
              </td>
              <td class="operate_td">
                <span v-if="item.status === 1" @click="flashCancel(item.id)" class="pointer">{{$t('myAdd.flash.cancel')}}</span>
                <span class="seeDetail pointer" @mouseenter="showSeeDetail(item.id)" @mouseleave="seeDetail = false">{{$t('myAdd.flash.lookDetail')}}</span>
                <div class="showDetailAlert front-color" v-if="seeDetailId === item.id && seeDetail">
                  <div class="side"><span>{{item.buyCoin}}</span><span> ➡ </span><span>{{item.sellCoin}}</span></div>
                  <div class="des">
                    <div class="fail" v-if="item.status === 2">
                      <p>
                        <i class="icon-close-circle fail_icon"></i>
                        {{$t('myAdd.flash.reason')}}: {{item.auditReason}}
                      </p>
                    </div>
                    <div class="canceled" v-if="item.status === 3">
                      <p>
                        <i class="icon-close-circle canceled_icon"></i>
                        {{$t('myAdd.flash.cancelTime')}} {{item.dtime}}
                      </p>
                    </div>
                    <div class="success" v-if="item.status === 0">
                      <p>
                        <i class="icon-true_icon1 suc_icon"></i>
                        {{$t('myAdd.flash.flashSuc')}} {{item.dtime}}
                      </p>
                    </div>
                    <div class="review" v-if="item.status === 1">
                      <p>
                        <i class="icon-clock review_icon"></i>
                        {{$t('myAdd.flash.reviewTip')}}
                      </p>
                     <!-- <p>
                        {{$t('myAdd.flash.revTime')}}: {{showToUser.stime}}-{{showToUser.etime}}
                      </p>-->
                    </div>
                  </div>
                  <div class="data">
                    <p><span class="data_text">{{$t('myAdd.flash.payMoney')}}</span><span class="data_num">{{item.allBuyNum}} {{item.buyCoin}}</span></p>
                    <p><span class="data_text">{{$t('myAdd.flash.exAmount')}}</span><span class="data_num">{{item.sellNum}} {{item.sellCoin}}</span></p>
                    <p><span class="data_text">{{$t('myAdd.flash.ratePrice')}}</span><span class="data_num">{{item.flashRate}}</span></p>
                    <p><span class="data_text">{{$t('myAdd.flash.serviceFee')}}</span><span class="data_num">{{item.buyFee}} {{item.buyCoin}}</span></p>
                    <p><span class="data_text">{{$t('myAdd.flash.flashNum')}}</span><span class="data_num">{{item.orderCode}}</span></p>
                    <p><span class="data_text">{{$t('myAdd.flash.subTime')}}</span><span class="data_num">{{item.ctime}}</span></p>
                  </div>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
        <noData v-if="!recordListLeng"></noData>
        <VPagination v-if="(flashPage.count/flashPage.pageSize) > 1"
                     :total="flashPage.count"
                     :current-page='flashPage.page'
                     :display='flashPage.pageSize'
                     @pagechange="flashPageChange($event)" class="page">
        </VPagination>
      </div>
    </div>
    <exchangePw :passWordAlert = "passWordAlert" @closePassWordAlert="closePassWordAlert" @submitRequest="submitRequest"></exchangePw>
    <span v-if="publicInfo"></span>
    <!-- 显示闪兑信息弹窗 -->
    <elDialog
      title= ''
      :flag= 'detailAlert'
      name= 'detailAlert'
      :width='450'
      :dialogClose='closeDialog'>
      <div class="detailTitle" slot="operation">
        {{$t('myAdd.flash.exchangeDetail')}}
      </div>
      <div class="detailAlertData" slot="content">
        <div class="side"><span>{{showToUser.buySymbol}}</span><i class="icon-uniE958"></i><span>{{showToUser.sellSymbol}}</span></div>
        <div class="data">
          <p><span class="text">{{$t('myAdd.flash.pay')}}</span><span class="num">{{myData.buyAllQuantity}}&nbsp;{{myData.buySymbol}}</span></p>
          <p><span class="text">{{$t('myAdd.flash.ex')}}</span><span class="num">{{myData.sellQuantity}}&nbsp;{{myData.sellSymbol}}</span></p>
          <p><span class="text">{{$t('myAdd.flash.ratePrice')}}</span><span class="num">{{myData.floatRate}}</span></p>
          <p><span class="text">{{$t('myAdd.flash.serviceFee')}}</span><span class="num">{{myData.feeQuantity}}&nbsp;{{myData.buySymbol}}</span></p>
        </div>
      </div>
      <div class="detailAlertFooter" slot="options">
        <button @click="closeDialog" class="cancel">{{$t('myAdd.flash.cancele')}}</button>
        <button @click="nextStep">{{$t('myAdd.flash.nextS')}}</button>
      </div>
    </elDialog>
    <!-- 提示实名认证弹窗 -->
    <elDialog
      title= ''
      :flag= 'realNameAlert'
      name= 'realNameAlert'
      :width= '450'
      :dialogClose= 'closeDialog'>
      <div class="realNameCont" slot="content">
        {{$t('myAdd.flash.c1verify')}}
      </div>
      <div slot="options">
        <button @click="closeDialog" class="cancel">{{$t('myAdd.flash.cancele')}}</button>
        <router-link tag="button" :to="{path: 'personal/information'}">{{$t('myAdd.flash.toVerify')}}</router-link>
      </div>
    </elDialog>
    <!-- 设置交易密码弹窗 -->
    <elDialog
      title= ''
      :flag= 'setExPw'
      name= 'setExPw'
      :width= '450'
      :dialogClose= 'closeDialog'>
      <div class="realNameCont" slot="content">
        {{$t('myAdd.flash.setExPassW')}}
      </div>
      <div slot="options">
        <button @click="closeDialog" class="cancel">{{$t('myAdd.flash.cancele')}}</button>
        <router-link tag="button" :to="{path: 'personal/setExPassW'}">{{$t('myAdd.flash.toSet')}}</router-link>
      </div>
    </elDialog>
  </div>
</template>

<script>
/*
*   this.timeOne = this.$t('typeTitle.fundsRate', { time: this.timeOne }) 这种方式可以传参
*   浮动汇率 =  返回的汇率  *  浮动比例；    实际汇率 = 返回的汇率 * （1 - 浮动汇率） ；  浮动差价 = （闪兑币种 - 手续费） * 浮动汇率； 浮动币种 是  收到的币种；
*   兑换100ETH里含有服务费,得到的数量应该是=(兑换数-服务费)x汇率；
*   显示汇率 = 汇率 * （ 1 - 浮动汇率）
* */
import InlineInput from '@/components/common/inlineInput'
import elDialog from '@/components/common/addCommon/dialog'
import VPagination from '@/components/common/pagination'
import noData from '@/components/addPage/common/noData'
import { mapState } from 'vuex'
import Datepicker from 'vuejs-datepicker'
import {en, zh, ko} from 'vuejs-datepicker/dist/locale'
import exchangePw from '@/components/common/addCommon/exchangePw'
import coinImg from '@/assets/img/coindef.png'
export default {
  name: 'flash',
  components: { InlineInput, elDialog, VPagination, noData, Datepicker, exchangePw },
  data () {
    return {
      formList: {},
      formStatus: {},
      detailAlert: false,
      passWordAlert: false,
      realNameAlert: false,
      setExPw: false, // 提示设置交易密码弹窗
      flashEntranceData: [],
      showToUser: {},
      myData: {
        id: null, // 闪兑配置ID
        buySymbol: null, // 兑换币种
        sellSymbol: null, // 收到币种
        buyAllQuantity: '', // 兑换币种数量（包含手续费）
        buyQuantity: '', // 兑换币种数量（不包含手续费）
        sellQuantity: '', // 收到币种数量
        rate: null, // 汇率
        feeQuantity: null, // 计算得出的服务费
        floatQuantity: null, // 浮动价格
        floatSymbol: null, // 浮动币种
        floatRate: null, // 浮动后的汇率(显示给用户看的)
        floatPrice: null, // 浮动差价 （汇率 * 浮动比例）
        isAudit: false, // 是否审核 使用 单笔 超过 多少 需要 审核  和  闪兑 次数超过 多少 需要审核  做判断
        errInfo: null // 不可闪兑 提示信息
      },
      isCanFastFlash: true, // 是否可以快速闪兑
      isInputValueYes: true,
      detailAlertData: {
        pay: null,
        get: null,
        price: null,
        serviceFee: null
      },
      seeDetail: false,
      seeDetailId: null,
      flashPage: {
        pageSize: 10,
        count: '',
        page: 1
      },
      userInfo: null,
      coinList: null,
      ifSetExchangePwd: 0,
      reviewCount: 0, // 审核中的币对数量
      recordList: [],
      recordListAxiosData: { // 请求闪兑记录的参数
        page: 1,
        pageSize: '',
        date: this.dateProcessing(new Date()),
        status: ''
      },
      token: null,
      secondClick: true,
      // datePicker
      flashRule: [], // 闪兑规则
      dataTimePickerValue: this.getLocalTime(),
      dataTimePickerLanguage: en,
      disabledDates: { // 限制时间选择范围  是 2018-12-31 --- 当前月
        to: new Date('Mon Dec 31 2018 19:47:00 GMT+0800 (中国标准时间)'),
        from: new Date(new Date().getTime() + 1000 * 60 * 60 * 24),
        daysOfMonth: undefined
      },
      formListOptionArrCopy: { // 存储 闪兑 兑换币种 和  收到 币种 得 集合
        flashCurrency: [],
        receivedCurrency: {}
      },
      coinImg: coinImg
    }
  },
  created () {
    this.formList = this.formList_obj
    this.formStatus = this.formStatus_obj
  },
  mounted () {
    this.recordListAxiosData.page = this.flashPage.page
    this.recordListAxiosData.pageSize = this.flashPage.pageSize
    this.setDateTimePickerLang(localStorage.getItem('lan')) // 设置 时间选择 插件 的  语言
  },
  computed: {
    ...mapState({
      publicInfo ({baseData}) {
        if (baseData.isReady) {
          this.userInfo = baseData._user
          this.userInfo && (this.ifSetExchangePwd = this.userInfo.ifSetExchangePwd)
          this.coinList = baseData._coinList
          this.flashRule = baseData.flashRule.split(';')
          return baseData
        } else {
          return false
        }
      }
    }),
    formList_obj () {
      return {
        flashCurrency: {  // 兑换货币的选择
          title: '',
          placeholder: '',
          formType: 'select',
          name: 'flashCurrency',
          value: '',
          optionList: []
        },
        flashNum: { // 兑换货币数量
          title: '',
          placeholder: this.Internationalization.quanty,
          formType: 'number',
          name: 'flashNum',
          value: ''  // 存储表单里面的值
        },
        receivedCurrency: {  // 收到货币的选择
          title: '',
          placeholder: '',
          formType: 'select',
          name: 'receivedCurrency',
          value: '',
          optionList: []
        },
        receivedNum: { // 收到货币数量
          title: '',
          placeholder: this.Internationalization.getNum,
          formType: 'number',
          name: 'receivedNum',
          value: ''  // 存储表单里面的值
        }
      }
    },
    Internationalization () {
      return {
        all: this.$t('myAdd.flash.all'), // 全部
        completed: this.$t('myAdd.flash.completed'), // 已完成
        waitReview: this.$t('myAdd.flash.waitReview'), // 待审核
        fail: this.$t('myAdd.flash.fail'), // 失败
        cancel: this.$t('myAdd.flash.cancel'), // 取消
        exPassW: this.$t('myAdd.flash.exPassW'), // 交易密码
        insuBalance: this.$t('myAdd.flash.insuBalance'), // 可用余额不足
        moreThenfastMaxQuantityOnce: this.$t('myAdd.flash.moreThenfastMaxQuantityOnce'), // 超出单次可兑换最大数量
        moreThenfastMinQuantityOnce: this.$t('myAdd.flash.moreThenfastMinQuantityOnce'), // 超出单次可兑换最小数量
        moreThenfastBalance: this.$t('myAdd.flash.moreThenfastBalance'), // 超出当天可兑换余额
        moreThenfastMaxQuantityDay: this.$t('myAdd.flash.moreThenfastMaxQuantityDay'),  // 超出当天可兑换最大数量
        reviewing: this.$t('myAdd.flash.reviewing'), // 当前币对,您有一笔订单处于审核中
        noflashBalance: this.$t('myAdd.flash.noflashBalance'), // 您该币种当天的兑换额度已经使用完了，请选择其他币种
        pleaseCheck: this.$t('myAdd.flash.pleaseCheck'), // 请检查
        Cancelled: this.$t('myAdd.flash.Cancelled'), // 已取消
        getNum: this.$t('myAdd.flash.getNum'), // 收到数量
        quanty: this.$t('myAdd.flash.quanty'), // 兑换数量
        flashSuc: this.$t('myAdd.flash.flashSuc'), // 兑换数量
        cancelSuc: this.$t('myAdd.flash.cancelSuc') // 取消成功
      }
    },
    formStatus_obj () {
      return {
        statusChoose: {
          title: '',
          placeholder: '',
          formType: 'select',
          name: 'statusChoose',
          value: 'all',
          optionList: [
            {value: this.Internationalization.all, code: 'all'},
            {value: this.Internationalization.completed, code: '0'},
            {value: this.Internationalization.waitReview, code: '1'},
            {value: this.Internationalization.fail, code: '2'},
            {value: this.Internationalization.Cancelled, code: '3'}
          ]
        }
      }
    },
    recordListLeng () {
      return this.recordList.length
    },
    flashCurrencyCoinImg () {
      if (this.coinList && this.formList.flashCurrency.value) {
        return this.coinList[this.formList.flashCurrency.value].icon
      }
    },
    receivedCurrencyCoinImg () {
      if (this.coinList && this.formList.receivedCurrency.value) {
        return this.coinList[this.formList.receivedCurrency.value].icon
      }
    }
  },
  watch: {
    'formList_obj' (val) {
      this.formList = val
    },
    'formStatus_obj' (val) {
      this.formStatus = val
    },
    userInfo (val) {
      val && val.authNewLevel === 'C0' && (this.realNameAlert = true)
      val && val.authNewLevel !== 'C0' && this.flashEntrance(), this.flashRecord()
    },
    'formList.flashCurrency.value' (val) { // 闪兑币种select
      const _this = this
      this.isCanFastFlash = true
      this.formList.flashCurrency.optionList.forEach((item) => {
        if (val && val === item.code) {
          this.formList.receivedCurrency.optionList = this.formListOptionArrCopy.receivedCurrency[val]
          this.formList.receivedCurrency.value = this.formList.receivedCurrency.optionList[0].code
          this.flashEntranceData.forEach((items) => {
            if (items.buySymbol === val && items.sellSymbol === _this.formList.receivedCurrency.value) {
              _this.showToUser = items
              // 关于是否可以闪兑做判断
              if (!_this.showToUser.isFalsh || (Number(_this.showToUser.flashQuantity) >= Number(_this.showToUser.fastMaxQuantityDay))) _this.isCanFastFlash = false
              _this.myData.buySymbol = items.buySymbol
            }
          })
        }
      })
      // 清空表单
      this.formList.flashNum.value = ''
      this.formList.receivedNum.value = ''
    },
    'formList.receivedCurrency.value' (val) { // 收到币种select
      this.isCanFastFlash = true
      this.flashEntranceData.forEach((item) => {
        if (item.sellSymbol === val && item.buySymbol === this.formList.flashCurrency.value) {
          this.showToUser = item
          // 关于是否可以闪兑做判断
          if (!this.showToUser.isFalsh || (Number(this.showToUser.flashQuantity) >= Number(this.showToUser.fastMaxQuantityDay))) this.isCanFastFlash = false
          this.myData.sellSymbol = item.sellSymbol
        }
      })
      // 清空表单
      this.formList.flashNum.value = ''
      this.formList.receivedNum.value = ''
    },
    showToUser (val) {
      val && (this.myData.floatRate = val.floatRate)
    },
    // 监听 语言切换
    '$store.state.baseData._lan' (val, old) {
      // 重新获取时间
      if (old) {
        this.setDateTimePickerLang(val)
        this.flashEntrance()
      }
    }
  },
  methods: {
    // 闪兑入口
    flashEntrance () {
      this.axios({
        url: this.$store.state.url.flash.flash_entrance,
        headers: {},
        params: {
          authLevel: this.userInfo.authNewLevel.toLowerCase()
        },
        method: 'post'
      }).then((res) => {
        if (res.code.toString() === '0') {
          this.formListOptionArrCopy = {
            flashCurrency: [],
            receivedCurrency: {}
          }
          this.flashEntranceData = []
          this.formList.flashCurrency.optionList = []
          this.formList.receivedCurrency.optionList = []
          this.reviewCount = res.data.count
          let data = res.data.mapList
          let buySymbolArr = []
          data.forEach((item) => {
            buySymbolArr.push(item.buySymbol)
            this.$set(this.formListOptionArrCopy.receivedCurrency, item.buySymbol, [])
          })
          this.formListOptionArrCopy.flashCurrency = Array.from(new Set(buySymbolArr))
          data.forEach((item) => {
            this.formListOptionArrCopy.receivedCurrency[item.buySymbol].push({value: item.sellSymbol, code: item.sellSymbol})
            item.balance = this._P.fixD(item.balance, this.coinList[item.buySymbol].showPrecision)
            this.flashEntranceData.push(item)
          })

          let buySymbolOptionArr = []
          this.formListOptionArrCopy.flashCurrency.forEach((item) => {
            let obj = {value: item, code: item}
            buySymbolOptionArr.push(obj)
          })
          this.formList.flashCurrency.optionList = buySymbolOptionArr
          this.formList.receivedCurrency.optionList = this.formListOptionArrCopy.receivedCurrency[this.formListOptionArrCopy.flashCurrency[0]]
          this.formList.flashCurrency.value = this.formList.flashCurrency.optionList[0].code
          this.formList.receivedCurrency.value = this.formList.receivedCurrency.optionList[0].code
          this.flashEntranceData.forEach((item) => {
            if (item.buySymbol === this.formList.flashCurrency.optionList[0].value && item.sellSymbol === this.formList.receivedCurrency.optionList[0].value) {
              this.showToUser = item
            }
          })
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
      })
    },
    somethings (val) {
      this.isInputValueYes = true
      this.myData.errInfo = null
      if (val.name === 'flashNum') {
        // 1可用余额做比较 2 与兑换限额（最大，最小）做比较 3 每天闪兑最大值做比较 4 与用户当天可闪兑币种余额作比较
        let newVal = val.value + ''
        let fixVal = newVal.split('.')[1]
        if (newVal) {
          let operationVal = this._P.fixInput(newVal, this.coinList[this.showToUser.buySymbol].showPrecision)
          let inputVal = Number(operationVal)
          this.checkInputValue(inputVal)
          if (this.isInputValueYes && operationVal) {
            // 兑换100ETH里含有服务费,得到的数量应该是=(兑换数-服务费)x汇率；
            this.myData.feeQuantity = this._P.lastD(this._P.fixD(this._P.accMul(operationVal, this.showToUser.fastFee), this.coinList[this.showToUser.buySymbol].showPrecision))
            this.myData.buyQuantity = this._P.accMul(operationVal, this._P.accSub(1, this.showToUser.fastFee))
            let receivedNum = this._P.accMul(this.myData.buyQuantity, this.myData.floatRate)
            this.formList.receivedNum.value = this._P.lastD(this._P.fixDUp(receivedNum, this.coinList[this.showToUser.sellSymbol].showPrecision))
          }
          if (fixVal && (fixVal.length > this.coinList[this.showToUser.buySymbol].showPrecision)) {
            this.$nextTick(() => {
              this.formList.flashNum.value = operationVal
            })
          }
        }
      }
      if (val.name === 'receivedNum') {
        this.isInputValueYes = true
        this.myData.errInfo = null
        let newVal = val.value + ''
        let fixVal = newVal.split('.')[1]
        if (newVal) {
          // 先计算得出 ‘兑换数量’ ， 再用兑换数量 去 判断
          // 公式：兑换数量 = 得到数量 / 汇率 / （）
          let operationVal = this._P.fixInput(newVal, this.coinList[this.showToUser.sellSymbol].showPrecision)
          let flashNum1 = this._P.accDiv(operationVal, this.myData.floatRate)
          let flashNum = this._P.accDiv(flashNum1, this._P.accSub(1, this.showToUser.fastFee))
          this.formList.flashNum.value = this._P.lastD(this._P.fixD(flashNum, this.coinList[this.showToUser.buySymbol].showPrecision))
          this.myData.feeQuantity = this._P.lastD(this._P.fixD(this._P.accMul(this.formList.flashNum.value, this.showToUser.fastFee), this.coinList[this.showToUser.buySymbol].showPrecision))
          this.checkInputValue(this.formList.flashNum.value)
          if (fixVal && (fixVal.length > this.coinList[this.showToUser.sellSymbol].showPrecision)) {
            this.$nextTick(() => {
              this.formList.receivedNum.value = operationVal
            })
          }
        }
      }
      if (val.name === 'statusChoose') {
        val.value.code !== 'all' ? this.recordListAxiosData.status = val.value.code : this.recordListAxiosData.status = ''
        this.restoreFirstPage()
        this.flashRecord()
      }
    },
    closeDialog () {
      this.detailAlert = false
      this.detailAlertData.pay = null
      this.detailAlertData.get = null
      this.detailAlertData.price = null
      this.detailAlertData.serviceFee = null
      this.realNameAlert = false
      this.setExPw = false
    },
    // 表单输入 条件判断
    checkInputValue (inputVal) {
      inputVal > Number(this.showToUser.balance) && (this.isInputValueYes = false, this.myData.errInfo = this.Internationalization.insuBalance) // 可用余额不足
      inputVal > Number(this.showToUser.fastMaxQuantityOnce) && (this.isInputValueYes = false, this.myData.errInfo = this.Internationalization.moreThenfastMaxQuantityOnce) // 超出单次可兑换最大数量
      inputVal < Number(this.showToUser.fastMinQuantityOnce) && (this.isInputValueYes = false, this.myData.errInfo = this.Internationalization.moreThenfastMinQuantityOnce) // 超出单次可兑换最小数量
      inputVal > (Number(this.showToUser.fastMaxQuantityDay) - Number(this.showToUser.flashQuantity)) && (this.isInputValueYes = false, this.myData.errInfo = this.Internationalization.moreThenfastBalance) // 超出当天可兑换余额
      inputVal > Number(this.showToUser.fastMaxQuantityDay) && (this.isInputValueYes = false, this.myData.errInfo = this.Internationalization.moreThenfastMaxQuantityDay) // 超出当天可兑换最大数量
    },
    // 点击快速闪兑
    fastFlash () {
      if (!this.isCanFastFlash) {
        !this.showToUser.isFalsh && (this.myData.errInfo = this.Internationalization.reviewing)
        this.showToUser.isFalsh && (this.myData.errInfo = this.Internationalization.noflashBalance)
        return false
      }
      if (!this.formList.flashNum.value || !this.formList.receivedNum.value || !this.isInputValueYes) {
        this.$store.dispatch('setTipState', {text: this.Internationalization.pleaseCheck, type: 'error'})
      } else {
        this.myData.id = this.showToUser.id
        this.myData.buyAllQuantity = this.formList.flashNum.value
        this.myData.sellQuantity = this.formList.receivedNum.value
        this.myData.rate = this.showToUser.rate
        // java规定浮动数量精度位8
        this.myData.floatQuantity = this._P.lastD(this._P.fixD(this.myData.rate * this.showToUser.fastFloat * this.myData.buyQuantity, 8))
        let isAudit1 = (this.myData.buyAllQuantity >= this.showToUser.firstAudit) ? true : false
        let isAudit2 = (this.showToUser.flashTime >= this.showToUser.flashTimeAudit) ? true : false
        this.myData.isAudit = isAudit1 || isAudit2
        this.myData.floatPrice = this.myData.rate * this.showToUser.fastFloat
        this.myData.floatSymbol = this.showToUser.sellSymbol
        this.detailAlert = true
      }
    },
    // 下一步
    nextStep () {
      if (!this.ifSetExchangePwd) {
        this.detailAlert = false
        this.setExPw = true
        return false
      }
      this.detailAlert = false
      this.passWordAlert = true
    },
    // 展示订单详情
    showSeeDetail (id) {
      this.seeDetailId = id
      this.seeDetail = true
    },
    // 闪兑详情分页
    flashPageChange (page) {
      this.flashPage.page = page
      this.recordListAxiosData.page = this.flashPage.page
      this.flashRecord()
    },
    // 快速闪兑请求
    submitPassw () {
      let { id, buySymbol, buyAllQuantity, buyQuantity, sellSymbol, sellQuantity, feeQuantity, floatQuantity, isAudit, rate, floatSymbol, floatRate, floatPrice } = this.myData
      let data = {id, buySymbol, buyAllQuantity, buyQuantity, sellSymbol, sellQuantity, feeQuantity, floatQuantity, isAudit, rate, floatSymbol, floatRate, floatPrice}
      this.axios({
        url: this.$store.state.url.flash.fast_exchange,
        headers: {},
        params: data,
        method: 'post'
      }).then(res => {
        if (res.code.toString() === '0') {
          this.flashRecord()
          this.flashEntrance()
          this.$store.dispatch('setTipState', {text: this.Internationalization.flashSuc})
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
        this.passWordAlert = false
      })
    },
    // 用户闪兑记录
    flashRecord () {
      this.axios({
        url: this.$store.state.url.flash.fast_exchange_order,
        headers: {},
        params: this.recordListAxiosData,
        method: 'post'
      }).then(res => {
        if (res.code.toString() === '0') {
          let data = res.data
          this.flashPage.count = data.count
          this.flashPage.pageSize = data.pageSize
          this.flashPage.page = data.page
          this.recordList = data.list
          this.recordList.forEach(item => {
            item.ctime = this._P.formatTime(item.ctime)
            item.dtime = this._P.formatTime(item.dtime)
          })
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
      })
    },
    // 记录状态
    recordListStatus (status) {
      let text = ''
      status === 0 && (text = this.Internationalization.completed)
      status === 1 && (text = this.Internationalization.waitReview)
      status === 2 && (text = this.Internationalization.fail)
      status === 3 && (text = this.Internationalization.Cancelled)
      return text
    },
    // 闪兑取消
    flashCancel (id) {
      this.axios({
        url: this.$store.state.url.flash.fast_exchange_cancel,
        headers: {},
        params: { orderId: id },
        method: 'post'
      }).then(res => {
        if (res.code.toString() === '0') {
          this.flashEntrance()
          this.flashRecord()
          this.$store.dispatch('setTipState', {text: this.Internationalization.cancelSuc})
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
      })
    },
    // 日期处理
    dateProcessing (date) {
      function s (t) {
        return t < 10 ? '0' + t : t
      }
      let y = date.getFullYear()
      let m = s(date.getMonth() + 1)
      return y + '-' + m
    },
    // 选择日期
    chooseMonth (e) {
      this.recordListAxiosData.date = this.dateProcessing(e)
      this.restoreFirstPage()
      this.flashRecord()
    },
    // 初始化 第一页
    restoreFirstPage () {
      this.flashPage.page = 1  // 当日期改变的时候 分页要变成第一页
      this.recordListAxiosData.page = this.flashPage.page
    },
    // 获取当前时间
    getLocalTime () {
      return new Date()
    },
    // 根据当前网站的语言环境 设置 时间选择插件的 语言
    setDateTimePickerLang (val) {
      switch (val) {
        case 'zh_CN':
          this.dataTimePickerLanguage = zh
          break
        case 'en_US':
          this.dataTimePickerLanguage = en
          break
        case 'ko_KR':
          this.dataTimePickerLanguage = ko
          break
        case 'el_GR':
          this.dataTimePickerLanguage = zh
          break
      }
    },
    closePassWordAlert () {
      this.passWordAlert = false
    },
    submitRequest () {
      this.submitPassw()
    }
  }
}
</script>

